<?php
namespace Home\Common;

class MissionLog extends Mysql{
	function __construct(){
		parent::__construct();
	}
	
	function getMissionLog(){
		$date = session('mog_thedate');
		$serverid = session('mog_serverid');
		
		$acceptResult = $this->mysql->prepare("select a.missionid,b.missionname,count(a.missionid) acceptnum from mog_mission_accept a , mog_mission_info b  
				where a.missionid = b.missionid and thedate = \"$date\" and a.serverid = $serverid group by missionid order by b.missionorder");
		/*
		$acceptResult = $this->mysql->prepare("select missionid,count(missionid) acceptnum from mog_mission_accept 
				where thedate = \"$date\" and serverid = \"$serverid\" group by missionid");
				*/
		$acceptResult->execute();
		$arResult=array();

		while($row=$acceptResult->fetch(\PDO::FETCH_ASSOC)){
			$arResult[$row['missionname']]=array('accept'=>$row['acceptnum'],'missionid'=>$row['missionid']);
			//$arResult[$row['missionid']] = array('accept'=>$row['acceptnum'], 'achive' => 0);
		}
		
		$archiveResult = $this->mysql->prepare("select a.missionid,b.missionname,count(a.missionid) achivenum from mog_mission_achive a , mog_mission_info b  
				where a.missionid = b.missionid and thedate = \"$date\" and a.serverid = \"$serverid\" group by missionid order by b.missionorder");
		/*
		$archiveResult = $this->mysql->prepare("select missionid,count(missionid) achivenum from mog_mission_achive 
				where thedate = \"$date\" and serverid = \"$serverid\" group by missionid");
				*/
		$archiveResult->execute();
		
		while($row=$archiveResult->fetch(\PDO::FETCH_ASSOC)){
			
			if(!isset($arResult[$row['missionname']]['accept'])) $arResult[$row['missionname']]['accept']=0;
			$arResult[$row['missionname']]=array('accept'=>$arResult[$row['missionname']]['accept'],'achive'=>$row['achivenum'],'missionid'=>$row['missionid']);
			/*
			if(!isset($arResult[$row['missionid']]['accept'])) $arResult[$row['missionid']]['accept'] = 0;
			$arResult[$row['missionid']] = array('accept' => $arResult[$row['missionid']]['accept'], 'achive' => $row['achivenum']);
			*/
		}
		
		return $arResult;
	}
}